<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('可选课程')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="role-form">
                <div class="select-list">
                    <ul>
                        <li>
                            课程号：<input name="courseId" type="text"/>
                        </li>
                        <li>
                            课程名称：<input name="courseName" type="text"/>
                        </li>
                        <li>
                            任课教师姓名：<input name="teacherName" type="text"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <b th:text="'本学期已选修课程总计 ' + ${score1} + ' 学分，还可选修 ' + ${score2} + ' 学分课程'"></b>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var addFlag = [[${@permission.hasPermi('system:optional:add')}]];
    var prefix = ctx + "project/stuandcou";


    $(function () {
        var options = {
            url: ctx + "project/course/selectCourse",
            createUrl: prefix + "/stuAddCourse",
            sortName: "courseId",
            modalName: "课程",
            columns: [
                {
                    field: 'courseId',
                    title: '课程号',
                    sortable: true
                },
                {
                    field: 'courseName',
                    title: '课程名称'
                },
                {
                    field: 'teacherId',
                    title: '任课教师号'
                },
                {
                    field: 'teacherName',
                    title: '任课教师姓名',
                },
                {
                    field: 'courseTime',
                    title: '学时',
                    sortable: true
                },
                {
                    field: 'coursePoint',
                    title: '学分',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="addCourse(\'' + row.courseId + '\')"><i class="fa fa-plus"></i>选课</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    // 添加课程
    function addCourse(id) {
        table.set();
        $.modal.confirm("确定添加本门" + table.options.modalName + "吗？", function () {
            var url = $.common.isEmpty(id) ? table.options.createUrl : table.options.createUrl.replace("{id}", id);
            if (table.options.type == table_type.bootstrapTreeTable) {
                $.operate.get(url);
            } else {
                var data = {"ids": id};
                $.operate.submit(url, "post", "json", data);
            }
        });
    }

    // 批量添加课程
    function addCourseAll() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        $.modal.confirm("确认要添加" + rows.length + "门课程吗?", function () {
            var url = table.options.createUrl;
            var data = {"ids": rows.join()};
            $.operate.submit(url, "post", "json", data);
        });
    }

</script>
</body>
</html>